import pymysql
import time

while True:
    host1 = "gz-cdb-5gusw5gx.sql.tencentcdb.com"
    host2 = "gz-cdbro-jhhihuc1.sql.tencentcdb.com"
    username = "wangzhijing"
    password1 = "wangzhijing"
    password2 = "ONSzyDLr"
    dbname1 = "hardware_open"
    dbname2 = "pos_manage"
    port1 = 63044
    port2 = 63950
    db1 = pymysql.connect(host1, username, password1, dbname1, port1)
    db2 = pymysql.connect(host2, username, password2, dbname2, port2)
    cursor1 = db1.cursor()
    cursor2 = db2.cursor()
    x = str(input("请输入要查询appid的sn："))
    if 13 < len(x) < 24:
        sql1 = "SELECT appid,sn,password,token FROM hardware_list WHERE sn='" + x + "'"
        sql2 = "SELECT pjname FROM pos_manage WHERE imei='" + x + "'"
        cursor1.execute(sql1)
        cursor2.execute(sql2)
        result1 = cursor1.fetchall()
        result2 = cursor2.fetchall()
        print(str(result2).strip("((),)"), ",", str(result1).strip("((),)"))
        db1.close()
        db2.close()
        time.sleep(20)
        break
    else:
        print("输入错误，重新输入！")
        continue
